Assignemnt #97 and 97th program
Code
///Name: Derrick Andreasen
///Period: 7
///Program name: 97th Program
///File name: Ninty7prog.java
///Date Finished:3/16/2016
import java.util.Scanner;
public class Ninty7prog
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int shape, radius, length, width, side, base, height;
System.out.println( "Shape Area Calculator" );
do
{
System.out.println( "\n_=_=_=_=_=_=_=_=_=_=_=_\n1) Triangle\n2) Rectangle\n3)Square\n4)Circle\n5)Quite\nWhich shape: " );
shape = keyboard.nextInt();
if(shape==1)
{
System.out.print( "Base: " );
base = keyboard.nextInt();
System.out.print( "Height: " );
height = keyboard.nextInt();
System.out.println( "The area is " + triangle(base, height) );
}
else if(shape==2)
{
System.out.print( "Length: " );
length = keyboard.nextInt();
System.out.print( "Width: " );
width = keyboard.nextInt();
System.out.println( "The area is " + rectangle(length, width) );
}
else if(shape==3)
{
System.out.print( "Side: " );
side = keyboard.nextInt();
System.out.println( "The area is " + square(side) );
}
else if(shape==4)
{
System.out.print( "Radius: " );
radius = keyboard.nextInt();
System.out.println( "The area is " + circle(radius) );
}
else
Quit();
}while (shape != 5);
}
public static double triangle(int base, int height)
{
double area = base*height/2;
return area;
}
public static int rectangle(int length, int width)
{
int area = length*width;
return area;
}
public static int square(int side)
{
int area = side*side;
return area;
}
public static double circle(int radius)
{
double area = Math.PI*radius*radius;
return area;
}
public static String Quit()
{
String quit = "Goodbye";
return quit;
}
}
Picture of the output